package io.renren.modules.lanling.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.lanling.entity.InvoiceEntity;
import io.renren.modules.lanling.service.InvoiceService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 发票表
 *
 * @author LANLING
 * @email lanling@gmail.com
 * @date 2018-11-08 15:01:03
 */
@RestController
@RequestMapping("lanling/invoice")
public class InvoiceController {
    @Autowired
    private InvoiceService invoiceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("lanling:invoice:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = invoiceService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lanling:invoice:info")
    public R info(@PathVariable("id") Integer id){
        InvoiceEntity invoice = invoiceService.queryObject(id);

        return R.ok().put("invoice", invoice);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("lanling:invoice:save")
    public R save(@RequestBody InvoiceEntity invoice){
        invoice.setCreationTime(new Date( ));//创建时间
        invoiceService.insert(invoice);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("lanling:invoice:update")
    public R update(@RequestBody InvoiceEntity invoice){
        ValidatorUtils.validateEntity(invoice);
        invoiceService.update(invoice);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("lanling:invoice:delete")
    public R delete(@RequestBody Integer[] ids){
        invoiceService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
